﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KYO.DAL;
using ObjectPersistence;
using BusinessLayerHelper;

public partial class Admin_Controls_Mod_Information_InformationList : ListControlBase<Information>
{


    InformationAssembler inforService = new InformationAssembler();
    CategoryAssembler categoryService = new CategoryAssembler();
    PersistentList<Information> infors = new PersistentList<Information>();


    public override PersistentList<Information> GetListObjects
    {
        get
        {
            return infors;


        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        LoadCategoryData();
        if (!IsPostBack)
        {
            
            ToolbarBox1.Header = "Information Manager";
            List<UrlItem> urls = new List<UrlItem>();
            UrlItem url = new UrlItem();
            url.Text = "Create New";
            url.Url = DoAction.ActionPageView(PageView.Information, Action.CREATE);
            urls.Add(url);

            ToolbarBox1.Options = urls;
            infors = inforService.ReadCollectionAll();
            LoadData();

        }
    }

    void LoadCategoryData()
    {
        PersistentList<Category> categories = categoryService.ReadCollectionAll();
      
        ddl_Categories.DataSource = categories;
        ddl_Categories.DataTextField = "Title";
        ddl_Categories.DataValueField = "CategoryId";
        ddl_Categories.DataBind();
        ddl_Categories.Items.Insert(0, new ListItem("--Select--", "0"));
           
    }



    protected void ddl_Categories_SelectedIndexChanged(object sender, EventArgs e)
    {

        int categoryId = int.Parse(ddl_Categories.SelectedValue);
        infors = categoryService.ReadSingleByKey(categoryId).InformationColl;
        LoadData();
    }
}
